export function getElement(
    el,
    binding,
    NodeName,
    callback = () => { throw '没有定义检测事件' },
    special = () => { }
) {
    if (el.children && el.children.length > 0 && !NodeName.includes(el.tagName)) {
        for (let i = 0; i < el.children.length; i++) {
            getElement(el.children[i], binding, NodeName, callback, special);
        }
    } else {
        if (NodeName.includes(el.tagName)) {
            binding.push(el);
            special(el);
            el.check = () => {
                if (!callback(el)) {
                    // el.className += " checkEmpty";
                    return false;
                } else {
                    return true;
                }
            };
        }
    }
}
export function checkEmpty(binding) {
    // unique
    let uuid = undefined;
    // mark point
    let markPoint = undefined;
    // synchronous array
    let syncArray = [];
    // asynchronous array
    const asyncArray = [];
    // the result array
    const resultArray = [];
    // is array ?
    if(!(binding.value[0] instanceof Array))return
    const eleArray = binding.value[0]
    
    for (let el = 0; el < binding.value[0].length; el++) {
        const currentElement = binding.value[0][el]
        const checkResult = currentElement.check()
        if (currentElement.getAttribute("replace-check")) {
            if (uuid !== currentElement.getAttribute("empty-check")) {
                if (syncArray.length > 0) {
                    if (isNaN(+uuid)) {
                        resultArray.push(syncArray)
                    } else {
                        asyncArray.push([uuid, syncArray])
                    }
                    syncArray = []
                }
            }
            const point = currentElement.getAttribute("replace-check")
            if (resultArray[point] === undefined) {
                resultArray.push(checkResult);
            } else {
                resultArray[point] = checkResult;
            }
            continue
        }
        if (currentElement.getAttribute("async-check")) {
            const point = currentElement.getAttribute("async-check")
            if (uuid !== point) {
                if (isNaN(+uuid)) uuid = point
                if (syncArray.length > 0) {
                    console.log({ uuid });
                    asyncArray.push([uuid, syncArray])
                    uuid = point
                }
                syncArray = []
                syncArray.push(checkResult)
            } else {
                syncArray.push(checkResult)
                if (el === binding.value[0].length - 1) {
                    asyncArray.push([uuid, syncArray])
                }
            }
            continue
        }
        if (currentElement.getAttribute("empty-check")) {
            if (uuid !== currentElement.getAttribute("empty-check")) {
                uuid = currentElement.getAttribute("empty-check")
                if (syncArray.length > 0) {
                    resultArray.push(syncArray)
                    syncArray = []
                }
                syncArray.push(checkResult)
            } else {
                syncArray.push(checkResult)
                if (el === binding.value[0].length - 1) resultArray.push(syncArray)
            }
            continue
        }
        if (syncArray.length > 0) {
            resultArray.push(syncArray)
            syncArray = []
        }
        resultArray.push(checkResult);
    }
    asyncArray.sort((a, b) => a[0] - b[0])
    asyncArray.forEach(item => {
        resultArray.splice(item[0], 0, item[1]);
    })
    binding.value[1](resultArray);
}